using System;
using System.ComponentModel;
using DevExpress.CodeRush.Core;
using DevExpress.CodeRush.PlugInCore;
using CR.StyleCop.Naming;
using CR.StyleCop.Maintainability;
using CR.StyleCop.Documentation;

namespace CR.StyleCop
{
    public class CR_StyleCop : StandardPlugIn {
        private IContainer components;
        private IssueProvider interfaceNamesMustBeginWithI;
        private IssueProvider elementMustBeginWithUpperCaseLetter;
        private IssueProvider constFieldNamesMustBeginWithUpperCaseLetter;
        private IssueProvider nonPrivateReadonlyFieldsMustBeginWithUpperCaseLetter;
        private IssueProvider fieldNamesMustBeginWithLowerCaseLetter;
        private IssueProvider accessibleFieldsMustBeginWithUpperCaseLetter;
        private IssueProvider variableNamesMustNotBePrefixed;
        private IssueProvider fieldNamesMustNotBeginWithUnderscore;
        private IssueProvider fieldNamesMustNotContainUnderscore;
        private IssueProvider fieldNamesMustNotUseHungarianNotation;
        private IssueProvider fieldsMustBePrivate;
        private IssueProvider fileMayOnlyContainASingleClass;
        private IssueProvider fileMayOnlyContainASingleNamespace;
        private IssueProvider useBuiltInTypeAlias;
        private IssueProvider elementsMustBeDocumentedSearcher;

        /// <summary>
        /// Initializes a new instance of the CR_StyleCop class.
        /// </summary>
        public CR_StyleCop() {
            this.components = new System.ComponentModel.Container();
            this.interfaceNamesMustBeginWithI = new IssueProvider(components);
            this.elementMustBeginWithUpperCaseLetter = new IssueProvider(components);
            this.constFieldNamesMustBeginWithUpperCaseLetter = new IssueProvider(components);
            this.nonPrivateReadonlyFieldsMustBeginWithUpperCaseLetter = new IssueProvider(components);
            this.fieldNamesMustBeginWithLowerCaseLetter = new IssueProvider(components);
            this.accessibleFieldsMustBeginWithUpperCaseLetter = new IssueProvider(components);
            this.variableNamesMustNotBePrefixed = new IssueProvider(components);
            this.fieldNamesMustNotBeginWithUnderscore = new IssueProvider(components);
            this.fieldNamesMustNotContainUnderscore = new IssueProvider(components);
            this.fieldNamesMustNotUseHungarianNotation = new IssueProvider(components);
            this.fieldsMustBePrivate = new IssueProvider(components);
            this.fileMayOnlyContainASingleClass = new IssueProvider(components);
            this.fileMayOnlyContainASingleNamespace = new IssueProvider(components);
            this.useBuiltInTypeAlias = new IssueProvider(components);
            this.elementsMustBeDocumentedSearcher = new IssueProvider(components);
            InitializeComponents();
        }

        #region InitializePlugIn
        public override void InitializePlugIn() {
            base.InitializePlugIn();
        }
        #endregion

        #region FinalizePlugIn
        public override void FinalizePlugIn() {
            base.FinalizePlugIn();
        }
        #endregion

        #region Initialize code

        private void InitializeComponents() {
            BeginInit();
            
            InitInterfaceNamesMustBeginWithI();
            InitElementMustBeginWithUpperCaseLetter();
            InitConstFieldNamesMustBeginWithUpperCaseLetter();
            InitNonPrivateReadonlyFieldsMustBeginWithUpperCaseLetter();
            InitFieldNamesMustBeginWithLowerCaseLetter();
            InitAccessibleFieldsMustBeginWithUpperCaseLetter();
            InitVariableNamesMustNotBePrefixed();
            InitFieldNamesMustNotBeginWithUnderscore();
            InitFieldNamesMustNotContainUnderscore();
            InitFieldNamesMustNotUseHungarianNotation();
            InitFieldsMustBePrivate();
            InitFileMayOnlyContainASingleClass();
            InitFileMayOnlyContainASingleNamespace();
            InitUseBuiltInTypeAlias();
            InitElementsMustBeDocumentedSearcher();

            EndInit();
        }

        private void BeginInit() {
            ((ISupportInitialize)(this.interfaceNamesMustBeginWithI)).BeginInit();
            ((ISupportInitialize)(this.elementMustBeginWithUpperCaseLetter)).BeginInit();
            ((ISupportInitialize)(this.constFieldNamesMustBeginWithUpperCaseLetter)).BeginInit();
            ((ISupportInitialize)(this.nonPrivateReadonlyFieldsMustBeginWithUpperCaseLetter)).BeginInit();
            ((ISupportInitialize)(this.fieldNamesMustBeginWithLowerCaseLetter)).BeginInit();
            ((ISupportInitialize)(this.accessibleFieldsMustBeginWithUpperCaseLetter)).BeginInit();
            ((ISupportInitialize)(this.variableNamesMustNotBePrefixed)).BeginInit();
            ((ISupportInitialize)(this.fieldNamesMustNotBeginWithUnderscore)).BeginInit();
            ((ISupportInitialize)(this.fieldNamesMustNotContainUnderscore)).BeginInit();
            ((ISupportInitialize)(this.fieldNamesMustNotUseHungarianNotation)).BeginInit();
            ((ISupportInitialize)(this.fieldsMustBePrivate)).BeginInit();
            ((ISupportInitialize)(this.fileMayOnlyContainASingleClass)).BeginInit();
            ((ISupportInitialize)(this.fileMayOnlyContainASingleNamespace)).BeginInit();
            ((ISupportInitialize)(this.useBuiltInTypeAlias)).BeginInit();
            ((ISupportInitialize)(this.elementsMustBeDocumentedSearcher)).BeginInit();
            ((ISupportInitialize)(this)).BeginInit();
        }

        private void EndInit() {
            ((ISupportInitialize)(this.interfaceNamesMustBeginWithI)).EndInit();
            ((ISupportInitialize)(this.elementMustBeginWithUpperCaseLetter)).EndInit();
            ((ISupportInitialize)(this.constFieldNamesMustBeginWithUpperCaseLetter)).EndInit();
            ((ISupportInitialize)(this.nonPrivateReadonlyFieldsMustBeginWithUpperCaseLetter)).EndInit();
            ((ISupportInitialize)(this.fieldNamesMustBeginWithLowerCaseLetter)).EndInit();
            ((ISupportInitialize)(this.accessibleFieldsMustBeginWithUpperCaseLetter)).EndInit();
            ((ISupportInitialize)(this.variableNamesMustNotBePrefixed)).EndInit();
            ((ISupportInitialize)(this.fieldNamesMustNotBeginWithUnderscore)).EndInit();
            ((ISupportInitialize)(this.fieldNamesMustNotContainUnderscore)).EndInit();
            ((ISupportInitialize)(this.fieldNamesMustNotUseHungarianNotation)).EndInit();
            ((ISupportInitialize)(this.fieldsMustBePrivate)).EndInit();
            ((ISupportInitialize)(this.fileMayOnlyContainASingleClass)).EndInit();
            ((ISupportInitialize)(this.fileMayOnlyContainASingleNamespace)).EndInit();
            ((ISupportInitialize)(this.useBuiltInTypeAlias)).EndInit();
            ((ISupportInitialize)(this.elementsMustBeDocumentedSearcher)).EndInit();
            ((ISupportInitialize)(this)).EndInit();
        }

        private void InitInterfaceNamesMustBeginWithI() {
            this.interfaceNamesMustBeginWithI.Description = CR.StyleCop.Resource.InterfaceNamesMustBeginWithIDescription;
            this.interfaceNamesMustBeginWithI.DisplayName = "SA1302:InterfaceNamesMustBeginWithI";
            this.interfaceNamesMustBeginWithI.ProviderName = "InterfaceNamesMustBeginWithISearcher";
            this.interfaceNamesMustBeginWithI.Register = true;
            this.interfaceNamesMustBeginWithI.CheckCodeIssues += (sender, ea) => new InterfaceNamesMustBeginWithISearcher().CheckCodeIssues(ea);
        }

        private void InitElementMustBeginWithUpperCaseLetter() {
            this.elementMustBeginWithUpperCaseLetter.Description = CR.StyleCop.Resource.ElementMustBeginWithUpperCaseLetterDescription;
            this.elementMustBeginWithUpperCaseLetter.DisplayName = "SA1300:ElementMustBeginWithUpperCaseLetter";
            this.elementMustBeginWithUpperCaseLetter.ProviderName = "ElementMustBeginWithUpperCaseLetterSearcher";
            this.elementMustBeginWithUpperCaseLetter.Register = true;
            this.elementMustBeginWithUpperCaseLetter.CheckCodeIssues += (sender, ea) => new ElementMustBeginWithUpperCaseLetterSearcher().CheckCodeIssues(ea);
        }

        private void InitConstFieldNamesMustBeginWithUpperCaseLetter() {
            this.constFieldNamesMustBeginWithUpperCaseLetter.Description = Resource.ConstFieldNamesMustBeginWithUpperCaseLetterSearcherDescription;
            this.constFieldNamesMustBeginWithUpperCaseLetter.DisplayName = Resource.ConstFieldNamesMustBeginWithUpperCaseLetterSearcherDisplayName;
            this.constFieldNamesMustBeginWithUpperCaseLetter.ProviderName = Resource.ConstFieldNamesMustBeginWithUpperCaseLetterSearcherProviderName;
            this.constFieldNamesMustBeginWithUpperCaseLetter.Register = true;
            this.constFieldNamesMustBeginWithUpperCaseLetter.CheckCodeIssues += (sender, ea) => new ConstFieldNamesMustBeginWithUpperCaseLetterSearcher().CheckCodeIssues(ea);
        }

        private void InitNonPrivateReadonlyFieldsMustBeginWithUpperCaseLetter() {
            this.nonPrivateReadonlyFieldsMustBeginWithUpperCaseLetter.Description = "The name of a non-private readonly C# field must being with an upper-case letter.";
            this.nonPrivateReadonlyFieldsMustBeginWithUpperCaseLetter.DisplayName = "SA1304:NonPrivateReadonlyFieldsMustBeginWithUpperCaseLetter";
            this.nonPrivateReadonlyFieldsMustBeginWithUpperCaseLetter.ProviderName = "NonPrivateReadonlyFieldsMustBeginWithUpperCaseLetterSearcher";
            this.nonPrivateReadonlyFieldsMustBeginWithUpperCaseLetter.Register = true;
            this.nonPrivateReadonlyFieldsMustBeginWithUpperCaseLetter.CheckCodeIssues += (sender, ea) => new NonPrivateReadonlyFieldsMustBeginWithUpperCaseLetterSearcher().CheckCodeIssues(ea);
        }

        private void InitFieldNamesMustBeginWithLowerCaseLetter() {
            this.fieldNamesMustBeginWithLowerCaseLetter.Description = StyleCop.Resource.FieldNameMustBeginWithLowerCaseLetterDescription;
            this.fieldNamesMustBeginWithLowerCaseLetter.DisplayName = StyleCop.Resource.FieldNameMustBeginWithLowerCaseLetterDisplayName;
            this.fieldNamesMustBeginWithLowerCaseLetter.ProviderName = StyleCop.Resource.FieldNameMustBeginWithLowerCaseLetterProviderName;
            this.fieldNamesMustBeginWithLowerCaseLetter.Register = true;
            this.fieldNamesMustBeginWithLowerCaseLetter.CheckCodeIssues += (sender, ea) => new FieldNamesMustBeginWithLowerCaseLetterSearcher().CheckCodeIssues(ea);
        }

        private void InitAccessibleFieldsMustBeginWithUpperCaseLetter() {
            this.accessibleFieldsMustBeginWithUpperCaseLetter.Description = Resource.AccessibleFieldsMustBeginWithUpperCaseLetterDescription;
            this.accessibleFieldsMustBeginWithUpperCaseLetter.DisplayName = Resource.AccessibleFieldsMustBeginWithUpperCaseLetterDisplayName;
            this.accessibleFieldsMustBeginWithUpperCaseLetter.ProviderName = Resource.AccessibleFieldsMustBeginWithUpperCaseLetterProviderName;
            this.accessibleFieldsMustBeginWithUpperCaseLetter.Register = true;
            this.accessibleFieldsMustBeginWithUpperCaseLetter.CheckCodeIssues += (sender, ea) => new AccessibleFieldsMustBeginWithUpperCaseLetter().CheckCodeIssues(ea);
        }

        private void InitVariableNamesMustNotBePrefixed() {
            this.variableNamesMustNotBePrefixed.Description = "A field name is prefixed with m_ or s_.";
            this.variableNamesMustNotBePrefixed.DisplayName = "SA1308:VariableNamesMustNotBePrefixed";
            this.variableNamesMustNotBePrefixed.ProviderName = "VariableNamesMustNotBePrefixedSearcher";
            this.variableNamesMustNotBePrefixed.Register = true;
            this.variableNamesMustNotBePrefixed.CheckCodeIssues += (sender, ea) => new VariableNamesMustNotBePrefixedSearcher().CheckCodeIssues(ea);
        }

        private void InitFieldNamesMustNotBeginWithUnderscore() {
            this.fieldNamesMustNotBeginWithUnderscore.Description = StyleCop.Resource.FieldNamesMustNotBeginWithUnderscoreDescription;
            this.fieldNamesMustNotBeginWithUnderscore.DisplayName = StyleCop.Resource.FieldNamesMustNotBeginWithUnderscoreDisplayName;
            this.fieldNamesMustNotBeginWithUnderscore.ProviderName = StyleCop.Resource.FieldNamesMustNotBeginWithUnderscoreProviderName;
            this.fieldNamesMustNotBeginWithUnderscore.Register = true;
            this.fieldNamesMustNotBeginWithUnderscore.CheckCodeIssues += (sender, ea) => new FieldNamesMustNotBeginWithUnderscore().CheckCodeIssues(ea);
        }

        private void InitFieldNamesMustNotContainUnderscore() {
            this.fieldNamesMustNotContainUnderscore.Description = StyleCop.Resource.FieldNamesMustNotContainUnderscoreDescription;
            this.fieldNamesMustNotContainUnderscore.DisplayName = StyleCop.Resource.FieldNamesMustNotContainUnderscoreDisplayName;
            this.fieldNamesMustNotContainUnderscore.ProviderName = StyleCop.Resource.FieldNamesMustNotContainUnderscoreProviderName;
            this.fieldNamesMustNotContainUnderscore.Register = true;
            this.fieldNamesMustNotContainUnderscore.CheckCodeIssues += (sender, ea) => new FieldNamesMustNotContainUnderscore().CheckCodeIssues(ea);
        }

        private void InitFieldNamesMustNotUseHungarianNotation() {
            this.fieldNamesMustNotUseHungarianNotation.Description = "The name of a field or variable must not uses Hungarian notation.";
            this.fieldNamesMustNotUseHungarianNotation.DisplayName = "SA1305:FieldNamesMustNotUseHungarianNotation";
            this.fieldNamesMustNotUseHungarianNotation.ProviderName = "FieldNamesMustNotUseHungarianNotationSearcher";
            this.fieldNamesMustNotUseHungarianNotation.Register = true;
            this.fieldNamesMustNotUseHungarianNotation.CheckCodeIssues += (sender, ea) => new FieldNamesMustNotUseHungarianNotation().CheckCodeIssues(ea);
        }

         private void InitFieldsMustBePrivate() {
            this.fieldsMustBePrivate.Description = CR.StyleCop.Resource.FieldsMustBePrivateDescription;
            this.fieldsMustBePrivate.DisplayName = CR.StyleCop.Resource.FieldsMustBePrivateDisplayName;
            this.fieldsMustBePrivate.ProviderName = CR.StyleCop.Resource.FieldsMustBePrivateProviderName;
            this.fieldsMustBePrivate.Register = true;
            this.fieldsMustBePrivate.CheckCodeIssues += (sender, ea) => new FieldsMustBePrivate().CheckCodeIssues(ea);
        }

        private void InitFileMayOnlyContainASingleClass() {
            this.fileMayOnlyContainASingleClass.Description = Resource.FileMayOnlyContainASingleClassDescription;
            this.fileMayOnlyContainASingleClass.DisplayName = Resource.FileMayOnlyContainASingleClassDisplayName;
            this.fileMayOnlyContainASingleClass.ProviderName = Resource.FileMayOnlyContainASingleClassProviderName;
            this.fileMayOnlyContainASingleClass.Register = true;
            this.fileMayOnlyContainASingleClass.CheckCodeIssues += (sender, ea) => new FileMayOnlyContainASingleClass().CheckCodeIssues(ea);
        }

        private void InitFileMayOnlyContainASingleNamespace() {
            this.fileMayOnlyContainASingleNamespace.Description = Resource.FileMayOnlyContainASingleNamespaceDescription;
            this.fileMayOnlyContainASingleNamespace.DisplayName = Resource.FileMayOnlyContainASingleNamespaceDisplayName;
            this.fileMayOnlyContainASingleNamespace.ProviderName = Resource.FileMayOnlyContainASingleNamespaceProviderName;
            this.fileMayOnlyContainASingleNamespace.Register = true;
            this.fileMayOnlyContainASingleNamespace.CheckCodeIssues += (sender, ea) => new FileMayOnlyContainASingleNamespace().CheckCodeIssues(ea);
        }

        private void InitUseBuiltInTypeAlias() {
            this.useBuiltInTypeAlias.Description = CR.StyleCop.Resource.UseBuiltInTypeAliasDescription;
            this.useBuiltInTypeAlias.DisplayName = CR.StyleCop.Resource.UseBuiltInTypeAliasDisplayName;
            this.useBuiltInTypeAlias.ProviderName = CR.StyleCop.Resource.UseBuiltInTypeAliasProviderName;
            this.useBuiltInTypeAlias.Register = true;
            this.useBuiltInTypeAlias.CheckCodeIssues += (sender, ea) => new UseBuiltInTypeAliasSearcher().CheckCodeIssues(ea);
        }

        private void InitElementsMustBeDocumentedSearcher() {
            this.elementsMustBeDocumentedSearcher.Description = "bla bla bla";
            this.elementsMustBeDocumentedSearcher.DisplayName = "kaskdlakld";
            this.elementsMustBeDocumentedSearcher.ProviderName = "kdalskldkal";
            this.elementsMustBeDocumentedSearcher.Register = true;
            this.elementsMustBeDocumentedSearcher.CheckCodeIssues += (sender, ea) => new ElementsMustBeDocumentedSearcher().CheckCodeIssues(ea);
        }
        #endregion

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing) {
            if (disposing && (components != null)) {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

    }
}